<!doctype html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
    <meta name="renderer" content="webkit">
    <title>咨询量管理系统</title>
    <meta name="MSSmartTagsPreventParsing" content="True"/>
    <meta name="author" content="me@xiaoyan.me"/>
    <meta http-equiv="MSThemeCompatible" content="Yes"/>
    <meta http-equiv="X-Frame-Options" content="SAMEORIGIN ">
    <link rel="stylesheet" href="{{ __URL__ }}/static/assets/css/bootstrap.min.css"/>
    <link rel="stylesheet" href="{{ __URL__ }}/static/assets/css/osw.css"/>
</head>
<body id="yc_web_os">
<div class="desktop">
    <div href="user.list" class="app window link {{ UserPermission('UserViewList') }}" title="用户列表" window-title="用户列表">
        <img src="{{ __URL__ }}/static/assets/app/icon-user.png" alt=""/>
        <span>用户列表</span></div>
    <div href="group.list" class="app window link {{ UserPermission('UserViewList') }}" title="分组管理"
       window-title="分组管理" window-offset="800,500">
        <img src="{{ __URL__ }}/static/assets/app/icon-user-group.png" alt=""/>
        <span>分组管理</span></div>
    <div href="task.view.add" class="app window link {{ UserPermission('TaskAddView') }}" title="咨询信息录入"
       window-title="咨询信息录入" window-offset="900,500">
        <img src="{{ __URL__ }}/static/assets/app/icon-record.png" alt=""/>
        <span>咨询信息录入</span></div>
    <div href="task.list" class="app window link {{ UserPermission('TaskQueryView') }}" title="咨询信息查询"
       window-title="咨询信息查询" show-full="true" window-offset="1150,520">
        <img src="{{ __URL__ }}/static/assets/app/icon-query.png" alt=""/>
        <span>咨询信息查询</span></div>
    <div href="task.temp.list" class="app window link {{ UserPermission('TaskTempQueryView') }}" title="临时任务查询"
         window-title="临时任务查询" window-offset="1050,520">
        <img src="{{ __URL__ }}/static/assets/app/icon-task.png" alt=""/>
        <span>临时任务查询</span></div>
    <div href="charts/demo" class="app window link {{ UserPermission('ChartWeekData') }}" title="最近7天咨询量"
       window-title="最近7天咨询量" window-offset="800,500">
        <img src="{{ __URL__ }}/static/assets/app/icon-chart.png" alt=""/>
        <span>最近7天咨询量</span></div>
    <div href="model.list" class="app window link {{ UserPermission('SystemModel') }}" title="模型管理"
         window-title="模型管理" disabled-max="yes">
        <img src="{{ __URL__ }}/static/assets/app/icon-model.png" alt=""/>
        <span>模型管理</span></div>
    <div href="notification.list" class="app window link {{ UserPermission('Notification') }}" title="提醒查询"
         window-title="提醒查询" window-offset="800,500">
        <img src="{{ __URL__ }}/static/assets/app/icon-notice.png" alt=""/>
        <span>提醒查询</span></div>
    <div class="version">Power By YCMS@OSW V1.0</div>
    <div class="login-user-info">
        <p class="datetime-info"
<span>{{ current_date }}</span>
        </p>
    </div>
</div>
<div class="task-bar">
    <div class="task-bar-bg"></div>
    <div class="start">
        <span class="start-icon"></span>
    </div>
    <div id="os_task_bar"></div>

    <div class="login-info">
        欢迎您<span class="user-name">{{ login_user_info.nick_name }}</span>(<span class="user-group">{{ login_user_info.group_name }}</span>)
        &nbsp;|&nbsp;
        <a href="user.view.login" class="logout">退出</a>
    </div>

</div>
<div class="hidden">
    <div class="notification_wrapper">
        <a class="msg-close" href="#">×</a>
        <div class="content">'传入任意的文本或html'</div>
    </div>
</div>
<audio id="audio_msg">
    <source src="{{ __URL__ }}/static/assets/audio/msg.mp3">
</audio>
<script src="{{ __URL__ }}/static/assets/js/jquery-1.10.2.min.js" type="text/javascript"></script>
<script src="{{ __URL__ }}/static/assets/js/jquery.md5.js" type="text/javascript"></script>
<script src="{{ __URL__ }}/static/assets/js/bootstrap.min.js" type="text/javascript"></script>
<script src="{{ __URL__ }}/static/assets/layui/layer/layer.dev.js" type="text/javascript"></script>
<script src="{{ __URL__ }}/static/assets/js/os.core.js" type="text/javascript"></script>
<!--[if lt IE 9]>
<script src="{{ __URL__ }}/static/assets/js/html5shiv.min.js" type="text/javascript"></script>
<script src="{{ __URL__ }}/static/assets/js/respond.min.js" type="text/javascript"></script>
<![endif]-->
<script type="text/javascript">
    var __msgAudio = document.getElementById('audio_msg');
    var Audio = {
        playMsg:function(){__msgAudio.play();}
    };
    var ns_icon = '{{ __URL__ }}/static/assets/app/icon-osw.png';
    osw.win = {};
    osw.openTask = function(url){

        this.open(url,{
            area:['900px','500px'],
            title:'咨询任务详情'
//            noMax:true,
//            disableFull:true
        });
        return false;
    };
    osw.noticeOpenTask = function(who){
        var _url = '';
        if(typeof(who) == 'string'){
            _url ='task/' + who + '.html';
        }else{
            _url ='task/' + who.innerHTML + '.html';
        }
        return osw.openTask(_url);
    }
    $(function(){
        if (window.Notification){ //请求权限
            if(Notification.permission == 'granted'){
                Notification.requestPermission();
            }
        }
        Logger.setPriority(Logger.priority.error);
        $('body').on('click',function(e){
            $('.window').removeClass('active');
        });
        $('.window').on('click',function(e){
            e.stopPropagation();
            $('.window').removeClass('active');
            $(this).addClass('active');
           return false;
        });

        $('.window').on('click',function(){
            var opts = {};
            var link  = $(this);
            if(link.attr('window-offset')){
                var offset = link.attr('window-offset');
                if(offset.indexOf(',')) offset = offset.split(',');
                else offset = [offset];
                $(offset).each(function(i){offset[i] += 'px'; });
                opts['area'] = offset;
            }
            if(link.attr('disabled-max') && link.attr('disabled-max') == 'yes'){
                opts['noMax'] = true;
                opts['disableFull'] = true;
            }
            if(link.attr('window-title')) opts['title'] = link.attr('window-title')
            else opts['title'] = link.find('span').text()
            var ret = osw.open(link.attr('href'),opts);
            if(link.attr('show-full')){
                ret.full();
            }
            $('.window').removeClass('active');
            return false;
        });
        $(window).on('resize',osw.layoutDesktop)
        $('.start').on('click',function(){
            osw.notice('系统版本： <strong>V1.0 Preview</strong>',{layer:true});
            return false;
        });
        //构建桌面图标
        osw.layoutDesktop();
        var noticeIds = {};
        var noticesList = [];
        var noticesIdList = [];
        var notice_is_show = false;
        var notice_show_timer = null;
        var showNotice = function(){
            if(noticesIdList.length > 0 && notice_is_show == false){
                noticesIdList.shift();
                var notice = noticesList.shift();
                var title = notice['notice_title'] ? notice['notice_title'] : '你有新信息';
                Audio.playMsg();
                osw.notice('<span style="font-size: 16px;font-weight: bold;color: #F00;">['
                        +title+']</span><br>' + notice['notice_message'],notice,function(){
                    osw.notification.read(notice['nid']);
                    notice_is_show = false;
                    notice_show_timer = setInterval(showNotice,500);
                });
                notice_is_show = true;
                if(notice_show_timer) clearInterval(notice_show_timer);
            }
        };
        notice_show_timer = setInterval(showNotice,500);
        //读取信息
        osw.notification.notice(function(t,n){
            Logger.debug(t)
            Logger.debug(n)
            $(n).each(function(index,notice){
                if($.inArray(notice['nid'],noticesIdList) == -1){
                    noticesList.push(notice);
                    noticesIdList.push(notice['nid']);
                }
                return;
                if(noticeIds[notice['nid']]){return;}
                noticeIds[notice['nid']] = 'yes';
                var tilte = notice['notice_title'] ? notice['notice_title'] : '你有新信息';
                osw.notice('['+tilte+']<br>' + notice['notice_message'],function(){
                    osw.notification.read(notice['nid']);
                });
                return;
                if (window.Notification && Notification.permission == 'granted'){
                    var ns = new Notification(tilte,{
                        icon:ns_icon,
                        body:notice['notice_message']
                    });
    //                var ns = new Notification('你有新信息' + "\n" + notice['notice_message']);
                    ns.onclose = function(){
                        delete noticeIds[notice['nid']];
                        osw.notification.read(notice['nid']);
                    };
                    ns.onclick = function(){
                        delete noticeIds[notice['nid']];
                        osw.notification.read(notice['nid']);
                    };
                }
            })
        }).start(5);
    });
</script>
</body>
</html>